package com.jeesite.modules.dataScreen.service;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson2.JSONObject;
import com.jeesite.modules.dataScreen.dao.IndustryIndexDao;
import com.jeesite.modules.dataScreen.web.dto.IndustryIndexParam;
import com.jeesite.modules.dataScreen.web.vo.IndustryIndexVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class CreditApprovalService {
    @Autowired
    private IndustryIndexDao industryIndexDao;

    public JSONObject baseInformation() {
        Map<String, IndustryIndexVo> indexVoMap = doGetIndustryIndex("行业智治", "信用审批",
                "行政审批", null, "运输船舶强制报废预警数","船舶检验证书到期预警数",
                "一件事一次办办件量","交通政务服务好评率");
        JSONObject result = new JSONObject();
        result.put("scrapWarning", indexVoMap.get("运输船舶强制报废预警数"));
        result.put("expireWarning", indexVoMap.get("船舶检验证书到期预警数"));
        result.put("shipmentQuantity", indexVoMap.get("一件事一次办办件量"));
        result.put("goodService", indexVoMap.get("交通政务服务好评率"));

        return result;
    }

    public JSONObject trafficEngineering() {
        Map<String, IndustryIndexVo> indexVoMap = doGetIndustryIndex("行业智治", "信用审批",
                "交通信用", "审批处", "交通运输信用评价D级企业比率","交通运输信用评价D级从业人员比率",
                "交通工程建设信用评价D级企业比率","交通工程建设评价D级从业人员比率","道路运输万车失信率");
        indexVoMap.get("道路运输万车失信率").setUnit("人/万车");
        JSONObject result = new JSONObject();
        result.put("transportationEnterprise", indexVoMap.get("交通运输信用评价D级企业比率"));
        result.put("transportationPersonnel", indexVoMap.get("交通运输信用评价D级从业人员比率"));
        result.put("engineeringEnterprise", indexVoMap.get("交通工程建设信用评价D级企业比率"));
        result.put("engineeringPersonnel", indexVoMap.get("交通工程建设评价D级从业人员比率"));
        result.put("defaultRate", indexVoMap.get("道路运输万车失信率"));
        return result;
    }

    private Map<String, IndustryIndexVo> doGetIndustryIndex(String plate, String runway, String subRunway, String liabilityUnit, String... industryNames) {
        List<String> indicatorNames = CollUtil.toList(industryNames);
        IndustryIndexParam indexParam = IndustryIndexParam.builder().plate(plate).runway(runway).subRunway(subRunway).liabilityUnit(liabilityUnit).indicatorNames(indicatorNames).build();
        return industryIndexDao.findUnRealtimeAllBy(indexParam);
    }


}
